package cn.schoolwow.quickdao.module.database.ddl.query.flow.property;

import cn.schoolwow.quickdao.domain.entity.Entity;
import cn.schoolwow.quickdao.domain.entity.Property;
import cn.schoolwow.quickdao.domain.entity.common.TableColumn;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.domain.beanCopy.BeanCopy;

import java.util.ArrayList;
import java.util.List;

public class GetTableColumnListFlow implements BusinessFlow {

    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        Entity entity = flowContext.checkData("entity", Entity.class);

        List<TableColumn> tableColumnList = new ArrayList<>();
        for(Property property: entity.properties){
            TableColumn tableColumn = BeanCopy.cloneObject(property, TableColumn.class);
            tableColumn.strategy = property.strategy;
            tableColumnList.add(tableColumn);
        }
        flowContext.putTemporaryData("tableColumnList", tableColumnList);
    }

    @Override
    public String name() {
        return "获取数据库指定表的列表信息";
    }
}
